import $ from 'jQuery';
(function () {
    let $vue = new Vue({
        el: '.main-hook',
        data: {
            status:[{id: 0, name: '未绑定'}, {id: 1, name: '绑定'}],
            key:[{id:0,name:'IMIS号'},{id:1,name:'终端编号'},{id:2,name:'单灯编号'}],
            boxs: {
                box1: {show: true, hook: '.box1-hook', lock: true, url: '', params: {}},
                box2: {show: false, hook: '.box2-hook', url: '', params: {}},
                box3: {show: false, hook: '.box3-hook', url: '', params: {}},
                box4: {show: false, hook: '.box4-hook', url: '', params: {}}
            }
        },
        created: function () {
          /*所属项目下拉*/
          /*所属分组下拉*/
        },
        methods: {
            emitPage: function () {
                M.Page.load(this.boxs);
            },
            // 上一页
            prePage: function () {
                M.Page.prePage(this.boxs);
            },
            // 触发刷新页(当前显示的页面)
            refreshPage: function () {
                M.Page.refreshPage(this.boxs);
            },
            searchKey:function(){
                $('.search-hook').trigger('click');
            }
        },
        mounted: function () {
            this.$nextTick(() => {
                let tableHookName = '.sim-table-hook';
                let $accountBox = $('.sim-hook');
                var $form = $accountBox.find('.form-hook');
                // 查询
                $form.off('submit').on('submit', function () {
                    $(tableHookName).bootstrapTable('onCustomSearch');
                    return false;
                });
                var $tableHook = $accountBox.find(tableHookName).bootstrapTable({
                    scrollbar: 'sim-table-body',
                    striped: true, // 设置为 true 会有隔行变色效果
                    pagination: true, // true 显示分页
                    paginationDetail: true, // 分页详情
                    sidePagination: 'server', // 服务器端
                    method: 'post',
                    url: URI.OPERATE.SIM.LIST,
                    debug: false,
                    cache: false,
                    pageNumber: 1,
                    pageSize: 20,
                    pageList: [10, 20, 50, 100],
                    // fixedColumns: true,
                    customButton: '',
                    customQueryParams: function (params) {
                        var formParams = $form.serializeJson();
                        var queryParams = $.extend({}, params, formParams);
                        //console.log(queryParams);
                        return queryParams;
                    },
                    columns: [
                        {
                            field: 'imsiCode', title: 'IMSI编号', align: 'center', fixedLeft: true,tips:true
                        },
                        {
                            field: 'status', title: '状态', align: 'center', fixedLeft: true,tips:true,
                            formatter: function (val, rowData, index) {
                                return val == '0' ? '未绑定' : '绑定';
                            }
                        },
                        {
                            field: 'proName', title: '所属项目', align: 'center', fixedLeft: true,tips:true
                        },
                        {
                            field: 'groupName', title: '所属分组', align: 'center', fixedLeft: true,tips:true
                        },
                        {
                            field: 'onenetCode', title: '终端编号', align: 'center', fixedLeft: true,tips:true
                        },
                        {
                            field: 'lightCode', title: '单灯编号', align: 'center', fixedLeft: true,tips:true
                        },
                        {
                            field: 'lastDate', title: '最近更新时间', align: 'center', fixedLeft: true,tips:true
                        },
                        {
                            field: 'operate', title: '操作', align: 'center', fixedLeft: true,width: 180,
                            events: {
                                'click .detail-sim': function (e, value, rowData, index) {
                                    M.Page.emit(URI.OPERATE.SIM.DETAIL.PAGE);
                                    IOT.setSessionStore(URI.OPERATE.SIM.DETAIL.PAGE, JSON.stringify(rowData));
                                    return false;
                                }
                            },
                            formatter: function (value, row, index) {
                                let html = [];
                                if (M.Authority.checkAuthority('account-detail')) {
                                    html.push('<a class="detail-sim operate">详情</a>');
                                }
                                return html.join('');
                            }
                        }
                    ]
                });
                //权限——查看
                if (!M.Authority.checkAuthority('account-detail')&&!M.Authority.checkAuthority('account-modify')) {
                    $(tableHookName).bootstrapTable('hideColumn', 'operate');//隐藏列
                }
            });
        }
    });
})();